/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * editRoomState
 *
 * Created on Nov 13, 2011, 12:04:36 PM
 */
package pkg1;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;

/**
 * This class allows the user to modify the layout of a room
 * @author Nick
 */
public class EditRoomState extends javax.swing.JFrame {

    /** Creates new form UnmodifiableEditRoomState */
    public EditRoomState(Room room) {
        this.room = room;
        this.setTitle(room.getName());
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        disabled = new javax.swing.JRadioButton("Disabled", !room.isEnabled());
        disabled.addActionListener(disableRoomListener);
        enabled = new javax.swing.JRadioButton("Enabled", room.isEnabled());
        enabled.addActionListener(enableRoomListener);
        submitButton = new JButton();
        submitButton.addActionListener(closeListener);
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        numberOfRooms = new ButtonGroup();
        oneRoom = new javax.swing.JRadioButton("1", room.getNumberOfVisibleBeds() == 1);
        oneRoom.addActionListener(oneRoomListener);
        twoRooms = new javax.swing.JRadioButton("2", room.getNumberOfVisibleBeds() == 2);
        twoRooms.addActionListener(twoRoomListener);
        threeRooms = new javax.swing.JRadioButton("3", room.getNumberOfVisibleBeds() == 3);
        threeRooms.addActionListener(threeRoomListener);
        fourRooms = new javax.swing.JRadioButton("4", room.getNumberOfVisibleBeds() == 4);
        fourRooms.addActionListener(fourRoomListener);
        numberOfRooms.add(oneRoom);
        numberOfRooms.add(twoRooms);
        numberOfRooms.add(threeRooms);
        numberOfRooms.add(fourRooms);
        typeOfRoom = new ButtonGroup();
        criticalCare = new javax.swing.JRadioButton("Critical Care", room.isCriticalCare());
        criticalCare.addActionListener(setCriticalListener);
        normalCare = new javax.swing.JRadioButton("Normal", !room.isCriticalCare());
        normalCare.addActionListener(setNormalListener);
        typeOfRoom.add(criticalCare);
        typeOfRoom.add(normalCare);
        jLabel3 = new javax.swing.JLabel();
        enabledOrNot = new ButtonGroup();
        enabledOrNot.add(enabled);
        enabledOrNot.add(disabled);
        enableProperButtons();

        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("Number of Beds available in room:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Beds In This Room Will Be:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("This Room is:");

        submitButton.setText("OK");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(submitButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(oneRoom)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(twoRooms))
                            .addComponent(normalCare))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(criticalCare)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(threeRooms)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(fourRooms))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(enabled)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(disabled)))
                .addContainerGap(28, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(enabled)
                    .addComponent(disabled))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(twoRooms)
                    .addComponent(threeRooms)
                    .addComponent(fourRooms)
                    .addComponent(oneRoom))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(criticalCare)
                    .addComponent(normalCare)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(submitButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(UnmodifiableEditRoomState.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UnmodifiableEditRoomState.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UnmodifiableEditRoomState.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UnmodifiableEditRoomState.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new UnmodifiableEditRoomState().setVisible(true);
            }
        });
    }
    
    //listener for room1 radio button
    ActionListener oneRoomListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
                room.setNumberOfBeds(1);
        }
    };
    
    //listener for critical radio button
    ActionListener setCriticalListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
                room.setCritical(true);
        }
    };
    
    //listener for close option
    ActionListener closeListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
                EditRoomState.this.dispose();
        }
    };
    
    //listener for normal radio button
    ActionListener setNormalListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
                room.setCritical(false);
        }
    };
    
    //listener for enable radio button
    ActionListener enableRoomListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            room.setEnabled();
            enableProperButtons();
        }
    };
    
    //listener for disable radio button
    ActionListener disableRoomListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            room.setDisabled();
            enableProperButtons();
        }
    };
    
    //helper method to enable proper buttons 
    //based on room state
    private void enableProperButtons() {
        oneRoom.setEnabled(room.isEnabled());
        twoRooms.setEnabled(room.isEnabled());
        threeRooms.setEnabled(room.isEnabled());
        fourRooms.setEnabled(room.isEnabled());
        criticalCare.setEnabled(room.isEnabled());
        normalCare.setEnabled(room.isEnabled());
    }
    
    //listener for room2 radio button
    ActionListener twoRoomListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
                room.setNumberOfBeds(2);
        }
    };
    
    //listener for room3 radio button
    ActionListener threeRoomListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
                room.setNumberOfBeds(3);
        }
    };
    
    //listener for room4 radio button
    ActionListener fourRoomListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
                room.setNumberOfBeds(4);
        }
    };
            
    // Variables declaration - do not modify
    private JButton submitButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private ButtonGroup numberOfRooms;
    private ButtonGroup enabledOrNot;
    private ButtonGroup typeOfRoom;
    private javax.swing.JRadioButton oneRoom;
    private javax.swing.JRadioButton twoRooms;
    private javax.swing.JRadioButton threeRooms;
    private javax.swing.JRadioButton fourRooms;
    private javax.swing.JRadioButton criticalCare;
    private javax.swing.JRadioButton normalCare;
    private javax.swing.JRadioButton disabled;
    private javax.swing.JRadioButton enabled;
    
    private Room room;
    // End of variables declaration
}
